#encoding=utf8
'''
Created on 2012-9-21

@author: Administrator
'''
from Processor import Processor
from models.User import User
from models.UserModel import *
from pub import Func,UserDict
from pub.Config import Config
class UIMClass(Processor):
    '''
    指令：UIM(user info Mod)
    备注：用户修改信息
    输入格式：cmd #cmdID#userID#userNickName#age#province#area#desc
    输出格式 :  cmd #cmdID#result#userID#msg
    '''
    def __init__(self,):
        Processor.__init__(self,)
        self.__outdata=None
        self.__field = {}
    def dataValidtor(self,cmdContent):
        if (len(cmdContent)==6):
#            用户编号
            self.__field["userId"] = cmdContent[0]
#            用户昵称
            self.__field["userNickName"] = cmdContent[1]
#            用户年龄
            self.__field["userAge"] = cmdContent[2]
#            用户所在省份
            self.__field["userProvince"] = cmdContent[3]
#            用户地区
            self.__field["userArea"] = cmdContent[4]
#            用户签名
            self.__field["userSign"] = cmdContent[5]
            return True
        else:
            return False
    def ModifanInfo(self,):
        '''
        用户修改操作
        '''

        cUser = UserDict.getUserFromUserDictById(self.__field["userId"])
        returnValue=(Config.I_USER_MODIFAN_INFO_ERROR,cUser)
        if(cUser):
            cUser.set_user_nick_name(self.__field["userNickName"])
            cUser.set_user_age(self.__field["userAge"])
            cUser.set_user_province(self.__field["userProvince"])
            cUser.set_user_area(self.__field["userArea"])
            cUser.set_user_sign(self.__field["userSign"])
            mUser = UserModel()

            (resultInt,cUser) = mUser.modifanInfo(cUser)
            if(resultInt==Config.I_USER_MODIFAN_INFO_OK):
                UserDict.addToUserDict(cUser)
            returnValue = (resultInt,cUser)
        return returnValue
    def outData(self):
        '''
        输出执行结果集
        '''
        (modState,cUser) = self.ModifanInfo()
        result = Config.I_SYS_ZERO
        UserId = Config.I_SYS_ZERO
        if(modState==Config.I_USER_MODIFAN_INFO_OK):
            result = Config.I_SYS_ONE
            UserId = cUser.get_user_id()
        Func.debugInfo(modState)
        Command = "%s#%s#%s#%s#%s"%\
        (self._cmd,self._cmdId,result,UserId,modState)
        self._sockObj.sendLine(str(Command))
        return Config.I_SYS_ONE;